package com.prs.crm.action.taskmanager;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.courser.ui.TreeNode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.taskmanager.DelayApply;
import com.prs.crm.domain.taskmanager.DeptTaskResult;
import com.prs.crm.domain.taskmanager.PersonalTaskResult;
import com.prs.crm.domain.taskmanager.StateDispose;
import com.prs.crm.domain.taskmanager.TaskAllot;
import com.prs.crm.domain.taskmanager.TaskType;
import com.prs.crm.domain.warning.TaskRemind;
import com.prs.crm.domain.warning.WarnContent;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.taskmanager.DelayApplyService;
import com.prs.crm.service.taskmanager.DeptTaskResultService;
import com.prs.crm.service.taskmanager.PersonalTaskResultService;
import com.prs.crm.service.taskmanager.StateDisposeService;
import com.prs.crm.service.taskmanager.TaskAllotService;
import com.prs.crm.service.taskmanager.TaskTypeService;
import com.prs.crm.service.warning.TaskRemindService;
import com.prs.crm.service.warning.WarnContentService;
import com.prs.crm.tools.Datetools;

public class TaskAllotAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private PaginationSupport pagination1;
	private PaginationSupport pagination2;
	private TaskAllot taskAllot;
	private TaskAllotService taskAllotService;
	private List<TaskType> taskType;
	private TaskTypeService taskTypeService;
	private List<Person> person;
	private PersonService personService;
	private File upload;
	private String uploadFileName;
	private File uploads;
	private String uploadsFileName;
	private List<TaskAllot> allots;
	private StateDispose stateDispose;
	private StateDisposeService stateDisposeService; 
	private TaskRemindService taskRemindService;
	private DelayApply delayApply;
	private DelayApplyService delayApplyService;
	private String taskIds;
	private Collection<TreeNode> nodes;
	private WarnContent warncontent;
	private WarnContentService warncontentService;
	private PersonalTaskResult personalTaskResult;
	private PersonalTaskResultService personalTaskResultService;
	private String startA;
	private String startAA;
	private String startB;
	private String startBB;
	private String startC;
	private String startCC;
	private DeptTaskResult deptTaskResult;
	private DeptTaskResultService deptTaskResultService;
	
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public File getUploads() {
		return uploads;
	}
	public void setUploads(File uploads) {
		this.uploads = uploads;
	}
	public String getUploadsFileName() {
		return uploadsFileName;
	}
	public void setUploadsFileName(String uploadsFileName) {
		this.uploadsFileName = uploadsFileName;
	}
	public DeptTaskResult getDeptTaskResult() {
		return deptTaskResult;
	}
	public void setDeptTaskResult(DeptTaskResult deptTaskResult) {
		this.deptTaskResult = deptTaskResult;
	}
	public DeptTaskResultService getDeptTaskResultService() {
		return deptTaskResultService;
	}
	public void setDeptTaskResultService(DeptTaskResultService deptTaskResultService) {
		this.deptTaskResultService = deptTaskResultService;
	}
	public PersonalTaskResult getPersonalTaskResult() {
		return personalTaskResult;
	}
	public void setPersonalTaskResult(PersonalTaskResult personalTaskResult) {
		this.personalTaskResult = personalTaskResult;
	}
	public PersonalTaskResultService getPersonalTaskResultService() {
		return personalTaskResultService;
	}
	public void setPersonalTaskResultService(
			PersonalTaskResultService personalTaskResultService) {
		this.personalTaskResultService = personalTaskResultService;
	}
	public Collection<TreeNode> getNodes() {
		return nodes;
	}
	public void setNodes(Collection<TreeNode> nodes) {
		this.nodes = nodes;
	}
	public String getTaskIds() {
		return taskIds;
	}
	public void setTaskIds(String taskIds) {
		this.taskIds = taskIds;
	}
	public DelayApply getDelayApply() {
		return delayApply;
	}
	public void setDelayApply(DelayApply delayApply) {
		this.delayApply = delayApply;
	}
	public DelayApplyService getDelayApplyService() {
		return delayApplyService;
	}
	public void setDelayApplyService(DelayApplyService delayApplyService) {
		this.delayApplyService = delayApplyService;
	}
	public StateDispose getStateDispose() {
		return stateDispose;
	}
	public void setStateDispose(StateDispose stateDispose) {
		this.stateDispose = stateDispose;
	}
	public StateDisposeService getStateDisposeService() {
		return stateDisposeService;
	}
	public void setStateDisposeService(StateDisposeService stateDisposeService) {
		this.stateDisposeService = stateDisposeService;
	}
	public PaginationSupport getPagination2() {
		return pagination2;
	}
	public void setPagination2(PaginationSupport pagination2) {
		this.pagination2 = pagination2;
	}
	public PaginationSupport getPagination1() {
		return pagination1;
	}
	public void setPagination1(PaginationSupport pagination1) {
		this.pagination1 = pagination1;
	}
	public List<TaskAllot> getAllots() {
		return allots;
	}
	public void setAllots(List<TaskAllot> allots) {
		this.allots = allots;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public TaskAllot getTaskAllot() {
		return taskAllot;
	}
	public void setTaskAllot(TaskAllot taskAllot) {
		this.taskAllot = taskAllot;
	}
	public TaskAllotService getTaskAllotService() {
		return taskAllotService;
	}
	public void setTaskAllotService(TaskAllotService taskAllotService) {
		this.taskAllotService = taskAllotService;
	}
	public List<TaskType> getTaskType() {
		return taskType;
	}
	public void setTaskType(List<TaskType> taskType) {
		this.taskType = taskType;
	}
	public TaskTypeService getTaskTypeService() {
		return taskTypeService;
	}
	public void setTaskTypeService(TaskTypeService taskTypeService) {
		this.taskTypeService = taskTypeService;
	}
	public List<Person> getPerson() {
		return person;
	}
	public void setPerson(List<Person> person) {
		this.person = person;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	/**领导查看*/
	@Action("listLeadSee")
	public String listLeadSee(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(TaskAllot.class);
		criteria.add(Restrictions.eq("agencyAllotPerson", AppContext.getAccountContext().getUser().getResume().getName()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getTaskAllotService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	/**代办任务
	 * @throws ParseException */
	@Action("listTaskComm")
	public String listTaskComm() throws ParseException{
		allots=this.getTaskAllotService().getAllTaskAllot();
		for (int i = 0; i <allots.size(); i++) {
			Date date=new Date();
			SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
			String dt=sf.format(date);
			Date dat=allots.get(i).getEndDate();
			String da=sf.format(dat);
			long num=sf.parse(dt).getTime();
			long num1=sf.parse(da).getTime();
			System.out.println(num);
			System.out.println(num1);
//			//结束时间
//			int num=(int)(date1);
//			//当前系统时间
//			int num1=(int)(date2);
//			
//			System.out.println("当前日期天数："+num);
//			System.out.println("页面中第"+(i+1)+"条数据的最后日期天数："+num1);
			int day=0;
//			System.out.println(allots.get(i).getType());
			if(num<num1 && "未完成".equals(allots.get(i).getType())){
				day=(int)((num1-num)/(1000*60*60*24));
				allots.get(i).setStateName("还有"+String.valueOf(day)+"天");
			}else if(num<num1 && "完成".equals(allots.get(i).getType())){
				day=(int)((num1-num)/(1000*60*60*24));
				allots.get(i).setStateName("提前"+String.valueOf(day)+"天");
			}else if(num1==num && "未完成".equals(allots.get(i).getType())){
				allots.get(i).setStateName("今日到期");
			}else if(num1==num && "完成".equals(allots.get(i).getType())){
				allots.get(i).setStateName("正常结束");
			}else if(num>num1 && "未完成".equals(allots.get(i).getType())){
				day=(int)((num-num1)/(1000*60*60*24));
				allots.get(i).setStateName("滞后"+String.valueOf(day)+"天");
			}else if(num>num1 && "完成".equals(allots.get(i).getType())){
				day=(int)((num-num1)/(1000*60*60*24));
				allots.get(i).setStateName("逾期"+String.valueOf(day)+"天");
			}
			this.getTaskAllotService().submit(allots.get(i));
		}
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(TaskAllot.class);
		criteria.add(Restrictions.eq("type", "未完成"));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getTaskAllotService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	/**已完成任务*/
	@Action("listTaskFinish")
	public String listTaskFinish(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(TaskAllot.class);
		criteria.add(Restrictions.eq("state", 100));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getTaskAllotService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	/**我分配的任务
	 * @throws ParseException */
	@Action("listMyTaskAllot")
	public String listMyTaskAllot() throws ParseException{
		allots=this.getTaskAllotService().getAllTaskAllot();
		for (int i = 0; i <allots.size(); i++) {
			if(allots.size()>0){
				Date date=new Date();
				SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
				String dt=sf.format(date);
				Date dat=allots.get(i).getEndDate();
				String da=sf.format(dat);
				long num=sf.parse(dt).getTime();
				long num1=sf.parse(da).getTime();
				
//				System.out.println(num);
//				System.out.println(num1);
//				System.out.println(dt);
//				System.out.println(da);
//				//系统时间
//				int nums=(int)(date1);
//				int num=Math.abs(nums);
//				//页面数据获取的时间
//				int num1s=(int)(date2);
//				int num1=Math.abs(num1s);
//				System.out.println(num);
//				System.out.println(num1);
				int day=0;
				if(num<num1 && "未完成".equals(allots.get(i).getType())){
					day=(int)((num1-num)/(1000*60*60*24));
					allots.get(i).setStateName("还有"+String.valueOf(day)+"天");
				}else if(num<num1 && "完成".equals(allots.get(i).getType())){
					day=(int)((num1-num)/(1000*60*60*24));
					allots.get(i).setStateName("提前"+String.valueOf(day)+"天");
				}else if(num1==num && "未完成".equals(allots.get(i).getType())){
					allots.get(i).setStateName("今日到期");	
				}else if(num1==num && "完成".equals(allots.get(i).getType())){
					allots.get(i).setStateName("正常结束");
				}else if(num>num1 && "未完成".equals(allots.get(i).getType())){
					day=(int)((num-num1)/(1000*60*60*24));
					allots.get(i).setStateName("滞后"+String.valueOf(day)+"天");
				}else if(num>num1 && "完成".equals(allots.get(i).getType())){
					day=(int)((num-num1)/(1000*60*60*24));
					allots.get(i).setStateName("逾期"+String.valueOf(day)+"天");
				}
				this.getTaskAllotService().submit(allots.get(i));
			}
		}
		/**查询全部的*/
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(TaskAllot.class);
			criteria.add(Restrictions.eq("agencyAllotPerson", AppContext.getAccountContext().getUser().getResume().getName()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getTaskAllotService().listByPage(criteria, pagination));
		
		/**查询未完成的*/
		DetachedCriteria criteria1=this.getPaginationHelper().createQuery(TaskAllot.class);
			criteria1.add(Restrictions.eq("agencyAllotPerson", AppContext.getAccountContext().getUser().getResume().getName()))
			.add(Restrictions.eq("type", "未完成"));	
		pagination1=this.getPaginationHelper().prepare(pagination1);
		this.setPagination1(this.getTaskAllotService().listByPage(criteria1, pagination1));
		
		/**查询完成的*/
		DetachedCriteria criteria2=this.getPaginationHelper().createQuery(TaskAllot.class);	
			criteria2.add(Restrictions.eq("agencyAllotPerson", AppContext.getAccountContext().getUser().getResume().getName()))
			.add(Restrictions.eq("type", "完成"));
		pagination2=this.getPaginationHelper().prepare(pagination2);
		this.setPagination2(this.getTaskAllotService().listByPage(criteria2, pagination2));
		return SUCCESS;
	}
	/**我完成的任务
	 * @throws ParseException */
	@Action("listMyFinishTaskAllot")
	public String listMyFinishTaskAllot() throws ParseException{
		allots=this.getTaskAllotService().getAllTaskAllot();
		for (int i = 0; i <allots.size(); i++) {
			if(allots.size()>0){	
				Date date=new Date();
				SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
				String dt=sf.format(date);
				Date dat=allots.get(i).getEndDate();
				String da=sf.format(dat);
				long num=sf.parse(dt).getTime();
				long num1=sf.parse(da).getTime();
//				//结束时间
//				int num=(int)(date1);
//				//当前系统时间
//				int num1=(int)(date2);
//				
//				System.out.println("当前日期天数："+num);
//				System.out.println("页面中第"+(i+1)+"条数据的最后日期天数："+num1);
				int day=0;
				System.out.println(allots.get(i).getType());
				if(num<num1 && "未完成".equals(allots.get(i).getType())){
					day=(int)((num1-num)/(1000*60*60*24));
					allots.get(i).setStateName("还有"+String.valueOf(day)+"天");
				}else if(num<num1 && "完成".equals(allots.get(i).getType())){
					day=(int)((num1-num)/(1000*60*60*24));
					allots.get(i).setStateName("提前"+String.valueOf(day)+"天");
				}else if(num1==num && "未完成".equals(allots.get(i).getType())){
					allots.get(i).setStateName("今日到期");
				}else if(num1==num && "完成".equals(allots.get(i).getType())){
					allots.get(i).setStateName("正常结束");
				}else if(num>num1 && "未完成".equals(allots.get(i).getType())){
					day=(int)((num-num1)/(1000*60*60*24));
					allots.get(i).setStateName("滞后"+String.valueOf(day)+"天");
				}else if(num>num1 && "完成".equals(allots.get(i).getType())){
					day=(int)((num-num1)/(1000*60*60*24));
					allots.get(i).setStateName("逾期"+String.valueOf(day)+"天");
				}
				this.getTaskAllotService().submit(allots.get(i));
			}
		}
		DetachedCriteria criteria2=this.getPaginationHelper().createQuery(TaskAllot.class);	
			criteria2.add(Restrictions.eq("agencyAllotPerson", AppContext.getAccountContext().getUser().getResume().getName()))
			.add(Restrictions.eq("type", "完成"));
		pagination2=this.getPaginationHelper().prepare(pagination2);
		this.setPagination2(this.getTaskAllotService().listByPage(criteria2, pagination2));
		return SUCCESS;
	}
	
	@Action("editTaskAllot")
	public String editTaskAllot(){
		person=this.getPersonService().getAllPersons();
		taskType=this.getTaskTypeService().getAllTaskType();
		return SUCCESS;
	}
	@Action("editTaskAllots")
	public String editTaskAllots(){
		person=this.getPersonService().getAllPersons();
		taskType=this.getTaskTypeService().getAllTaskType();
		return SUCCESS;
	}
	@Action("editAgencyTaskAllot")
	public String editAgencyTaskAllot(){
		person=this.getPersonService().getAllPersons();
		taskType=this.getTaskTypeService().getAllTaskType();
		return SUCCESS;
	}
	
	@Action("viewTaskAllot")
	public String viewTaskAllot(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(StateDispose.class);
		criteria.add(Restrictions.eq("taskAllot.id", taskAllot.getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getStateDisposeService().listByPage(criteria, pagination));
	
		DetachedCriteria criteria1=this.getPaginationHelper().createQuery(DelayApply.class);
		criteria1.add(Restrictions.eq("taskAllot.id", taskAllot.getId()));
		pagination1=this.getPaginationHelper().prepare(pagination1);
		this.setPagination1(this.getDelayApplyService().listByPage(criteria1, pagination1));
		return SUCCESS;
	}
	@Action("editUpdateState")
	public String editUpdateState(){
		return SUCCESS;
	}
	@Action("editUpdateDoState")
	public String editUpdateDoState(){
		return SUCCESS;
	}
	@Action("editDelay")
	public String editDelay(){
		DetachedCriteria criteria1=this.getPaginationHelper().createQuery(DelayApply.class);
		criteria1.add(Restrictions.eq("taskAllot.id", taskAllot.getId()));
		pagination1=this.getPaginationHelper().prepare(pagination1);
		this.setPagination1(this.getDelayApplyService().listByPage(criteria1, pagination1));
		return SUCCESS;
	}
	@Action("editDelays")
	public String editDelays(){
		DetachedCriteria criteria1=this.getPaginationHelper().createQuery(DelayApply.class);
		criteria1.add(Restrictions.eq("taskAllot.id", delayApply.getTaskAllot().getId()));
		pagination1=this.getPaginationHelper().prepare(pagination1);
		this.setPagination1(this.getDelayApplyService().listByPage(criteria1, pagination1));
		return SUCCESS;
	}
	@Action(value = "saveViewTaskAllot", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}") })
	public String saveViewTaskAllot(){
		this.getTaskAllotService().submit(taskAllot);
		return SUCCESS;
	}
	@Action(value = "saveTaskAllots", results = {
			@Result(name = "success", type = "redirect", location = "listMyTaskAllot"),
			@Result(name = "error", type = "chain", location = "listMyTaskAllot") })
	public String saveTaskAllots(){
		if(upload!=null){
			this.taskAllot.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		this.getTaskAllotService().submit(taskAllot);
		return SUCCESS;
	}
	@Action(value = "saveDelay", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "editDelay?taskAllot=${taskAllot.getId()}") })
	public String saveDelay(){
		Date date=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		this.getTaskAllotService().submit(taskAllot);
		delayApply.setTaskAllot(taskAllot);
		delayApply.setAppTime(sf.format(date));
		delayApply.setDelayPerson(per.getResume().getName());
		delayApply.setDelayReason(delayApply.getDelayReason());
		delayApply.setDelayDate(delayApply.getDelayDate());
		delayApply.setDelayTime(delayApply.getDelayTime());
		delayApply.setDelayIdea("1");
		this.getDelayApplyService().save(delayApply);
		return SUCCESS;
	}
	@Action(value = "saveAgree", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${delayApply.getTaskAllot().getId()}"),
			@Result(name = "error", type = "chain", location = "editDelays?taskAllot=${taskAllot.getId()}") })
	public String saveAgree(){
		if(delayApply.getDelayIdea()==null || "".equals(delayApply.getDelayIdea().trim())){
			this.addActionError("处理意见不能为空！");
			return ERROR;
		}

		delayApply.setTaskAllot(delayApply.getTaskAllot());
		delayApply.setDelayIdea(delayApply.getDelayIdea()+"（同步推迟任务计划结束时间）");
		this.getDelayApplyService().submit(delayApply);	
		delayApply.getTaskAllot().setId(delayApply.getTaskAllot().getId());
		delayApply.getTaskAllot().setEndDate(delayApply.getDelayDate());
		delayApply.getTaskAllot().setEndTime(delayApply.getDelayTime());
		this.getTaskAllotService().submit(delayApply.getTaskAllot());
		return SUCCESS;
	}
	@Action(value = "saveDisagree", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${delayApply.getTaskAllot().getId()}"),
			@Result(name = "error", type = "chain", location = "editDelays?taskAllot=${taskAllot.getId()}") })
	public String saveDisagree(){
		if(delayApply.getDelayIdea()==null || "".equals(delayApply.getDelayIdea().trim())){
			this.addActionError("处理意见不能为空！");
			return ERROR;
		}
		delayApply.getTaskAllot().setId(delayApply.getTaskAllot().getId());
		delayApply.setTaskAllot(delayApply.getTaskAllot());
		delayApply.setDelayIdea(delayApply.getDelayIdea()+"（保持任务计划结束时间不变）");
		this.getDelayApplyService().submit(delayApply);
		this.getTaskAllotService().submit(delayApply.getTaskAllot());
		return SUCCESS;
	}
	
	@Action(value = "saveState", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "viewUpdateState?taskAllot=${taskAllot.getId()}") })
	public String saveState() throws ParseException{
		this.getTaskAllotService().submit(taskAllot);
		Date dates=new Date();
		SimpleDateFormat sf1=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		PersonalTaskResult result=this.getPersonalTaskResultService().getPersonalTaskResults(per.getResume().getName());
		System.out.println(per.getDept().getName());
		DeptTaskResult result1=this.getDeptTaskResultService().getDeptTaskResult(per.getDept().getName());
		if(taskAllot.getState()==100){
			taskAllot.setFinishTime(sf1.format(dates));
			taskAllot.setRecordTime(new Date());
			taskAllot.setType("完成");
			this.getTaskAllotService().submit(taskAllot);
			Date date=new Date();
			SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
			String dt=sf.format(date);
			Date dat=taskAllot.getEndDate();
			String da=sf.format(dat);
			long num=sf.parse(dt).getTime();
			long num1=sf.parse(da).getTime();
			int day=0;
			
			if(num<num1 && "未完成".equals(taskAllot.getType())){
				day=(int)((num1-num)/(1000*60*60*24));
				taskAllot.setStateName("还有"+String.valueOf(day)+"天");
				result.setConductTaskNum(result.getConductTaskNum()+1);
//				result1.setConductTaskNum(result1.getConductTaskNum()+1);
				this.getPersonalTaskResultService().submit(result);
//				this.getDeptTaskResultService().submit(result1);
			}else if(num<num1 && "完成".equals(taskAllot.getType())){
				day=(int)((num1-num)/(1000*60*60*24));
				taskAllot.setStateName("提前"+String.valueOf(day)+"天");
				result.setConductTaskNum(result.getConductTaskNum()-1);
				result.setAheadTaskNum(result.getAheadTaskNum()+1);
//				result1.setConductTaskNum(result1.getConductTaskNum()-1);
//				result1.setAheadTaskNum(result1.getAheadTaskNum()+1);
				this.getPersonalTaskResultService().submit(result);
//				this.getDeptTaskResultService().submit(result1);
			}else if(num1==num && "未完成".equals(taskAllot.getType())){
				taskAllot.setStateName("今日到期");
				result.setConductTaskNum(result.getConductTaskNum()+1);
//				result1.setConductTaskNum(result1.getConductTaskNum()+1);
				this.getPersonalTaskResultService().submit(result);
//				this.getDeptTaskResultService().submit(result1);
			}else if(num1==num && "完成".equals(taskAllot.getType())){
				taskAllot.setStateName("正常结束");
				result.setConductTaskNum(result.getConductTaskNum()-1);
				result.setNormalTaskNum(result.getNormalTaskNum()+1);
//				result1.setConductTaskNum(result1.getConductTaskNum()-1);
//				result1.setNormalTaskNum(result1.getNormalTaskNum()+1);
				this.getPersonalTaskResultService().submit(result);
//				this.getDeptTaskResultService().submit(result1);
			}else if(num>num1 &&"未完成".equals(taskAllot.getType())){
				day=(int)((num-num1)/(1000*60*60*24));
				taskAllot.setStateName("滞后"+String.valueOf(day)+"天");
				result.setConductTaskNum(result.getConductTaskNum()+1);
//				result1.setConductTaskNum(result1.getConductTaskNum()+1);
				this.getPersonalTaskResultService().submit(result);
//				this.getDeptTaskResultService().submit(result1);
			}else if(num>num1 && "完成".equals(taskAllot.getType())){
				day=(int)((num-num1)/(1000*60*60*24));
				taskAllot.setStateName("逾期"+String.valueOf(day)+"天");
				result.setConductTaskNum(result.getConductTaskNum()-1);
				result.setDelayTaskNum(result.getDelayTaskNum()+1);
//				result1.setConductTaskNum(result1.getConductTaskNum()-1);
//				result1.setDelayTaskNum(result1.getDelayTaskNum()+1);
				this.getPersonalTaskResultService().submit(result);
//				this.getDeptTaskResultService().submit(result1);
			}
			this.getTaskAllotService().submit(taskAllot);
		}
		stateDispose=new StateDispose();
		stateDispose.setTaskAllot(taskAllot);
		this.stateDispose.setFeedbackPerson(per.getResume().getName());
		if(taskAllot.getIdea()==null || "".equals(taskAllot.getIdea().trim())){
			this.stateDispose.setContent(per.getResume().getName()+"将"+taskAllot.getAgencyAllotPerson()+"的任务进度修改为"+taskAllot.getState()+"%。");	
		}else{
			this.stateDispose.setContent(per.getResume().getName()+"将"+taskAllot.getAgencyAllotPerson()+"的任务进度修改为"+taskAllot.getState()+"%。"+per.getResume().getName()+"的意见："+taskAllot.getIdea());
		}
		
		this.stateDispose.setTime(sf1.format(dates));
		this.getStateDisposeService().save(stateDispose);
		return SUCCESS;
	}
	@Action(value = "saveDoState", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "viewUpdateState?taskAllot=${taskAllot.getId()}") })
	public String saveDoState(){
		this.getTaskAllotService().submit(taskAllot);
		Date date=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		if(taskAllot.getDoState()==100){
			taskAllot.setDoFinishTime(sf.format(date));
			taskAllot.setDoType("完成");
			this.getTaskAllotService().submit(taskAllot);
		}
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		stateDispose=new StateDispose();
		stateDispose.setTaskAllot(taskAllot);
		this.stateDispose.setFeedbackPerson(per.getResume().getName());
		if(taskAllot.getIdea()==null || "".equals(taskAllot.getIdea().trim())){
			this.stateDispose.setContent(per.getResume().getName()+"将"+taskAllot.getDoPerson()+"的任务进度修改为"+taskAllot.getDoState()+"%。");	
		}else{
			this.stateDispose.setContent(per.getResume().getName()+"将"+taskAllot.getDoPerson()+"的任务进度修改为"+taskAllot.getDoState()+"%。"+per.getResume().getName()+"的意见："+taskAllot.getIdea());
		}
		
		this.stateDispose.setTime(sf.format(date));
		this.getStateDisposeService().save(stateDispose);
		return SUCCESS;
	}
	@Action(value = "saveUpdate", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}") })
	public String saveUpdate(){
		taskAllot.setType("未完成");
		this.getTaskAllotService().submit(taskAllot);
		return SUCCESS;
	}
	@Action(value = "saveUpdates", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}") })
	public String saveUpdates(){
		taskAllot.setDoType("未完成");
		this.getTaskAllotService().submit(taskAllot);
		return SUCCESS;
	}

	
	@Action(value = "saveTaskAllot", results = {
			@Result(name = "success", type = "redirect", location = "listMyTaskAllot"),
			@Result(name = "error", type = "chain", location = "editTaskAllot") })
	public String saveTaskAllot() throws ParseException{
		if(upload!=null){
			this.taskAllot.setAttach(FileUtil.getInstance().createAttach(upload, uploadFileName));
		}
		if (taskAllot.getTitle()==null ||"".equals(taskAllot.getTitle().trim())) {
			this.addActionError("任务标题不能为空！");
			return ERROR;
		}
		if (taskAllot.getDutyPerson()==null || "".equals(taskAllot.getDutyPerson())) {
			this.addActionError("负责人不能为空！");
			return ERROR;
		}
		if (taskAllot.getStartDate()==null || "".equals(taskAllot.getStartDate()) || taskAllot.getEndDate()==null || "".equals(taskAllot.getEndDate())) {
			this.addActionError("开始和结束时间不能为空！");
			return ERROR;
		}	
		Datetools  dt=new Datetools();
		Date startTime=taskAllot.getStartDate();
		Date endTime  =taskAllot.getEndDate();
		/**
		 * 分配人
		 * 当前分配任务的人
		 */
		if(taskAllot.getRemindAllotPerosn())
		{
		Person p=AppContext.getAccountContext().getUser();	

		if(taskAllot.getSendSysInfo())//发送系统消息
		{
			
			if(taskAllot.getStartRemind())//任务开始前提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务即将开始");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("开始之前");
				t1.setSendtype("系统");
				this.getTaskRemindService().save(t1);
				
			}
			if(taskAllot.getStartRemind())//任务结束前提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务即将结束");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("结束之前");
				t1.setSendtype("系统");
				this.getTaskRemindService().save(t1);
			}
			if(taskAllot.getStartRemind())//任务超期后提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务已超期");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("超期之后");
				t1.setSendtype("系统");
				this.getTaskRemindService().save(t1);
			}
			
			
//			WarnContent wc=new WarnContent();
//			wc.setWarnstyl("任务:"+taskAllot.getTitle());
//			wc.setWarnCont("你对任务:"+taskAllot.getTitle()+"进行了分配");
//		    wc.setReceivID(p.getId()+"");
//			this.getWarncontentService().save(wc);	
		}
		if(taskAllot.getSendMobile())//发送手机短信
		{
			if(taskAllot.getStartRemind())//任务开始前提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务即将开始");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("开始之前");
				t1.setSendtype("短信");
				this.getTaskRemindService().save(t1);
				
			}
			if(taskAllot.getStartRemind())//任务结束前提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务即将结束");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("结束之前");
				t1.setSendtype("短信");
				this.getTaskRemindService().save(t1);
			}
			if(taskAllot.getStartRemind())//任务超期后提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务已超期");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("超期之后");
				t1.setSendtype("短信");
				this.getTaskRemindService().save(t1);
			}
			
		}
		if(taskAllot.getSendEmail())//发送email
		{

			if(taskAllot.getStartRemind())//任务开始前提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务即将开始");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("开始之前");
				t1.setSendtype("邮件");
				this.getTaskRemindService().save(t1);
				
			}
			if(taskAllot.getStartRemind())//任务结束前提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务即将结束");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("结束之前");
				t1.setSendtype("邮件");
				this.getTaskRemindService().save(t1);
			}
			if(taskAllot.getStartRemind())//任务超期后提醒
			{
				TaskRemind t1=new TaskRemind();
				t1.setReState("1");
				t1.setReContent(taskAllot.getTitle()+"任务已超期");
				t1.setReId(p.getId()+"");
				t1.setRestyle("分配任务");
				t1.setRestartTime(dt.getstrTime(startTime));
				t1.setReendTime(dt.getstrTime(endTime));
				t1.setResty("超期之后");
				t1.setSendtype("邮件");
				this.getTaskRemindService().save(t1);
			}
			
		}
			
	
		
		}
		
		/**
		 * 发布人
		 * 当前发布任务的人
		 */
		if(taskAllot.getRemindAllotPerosn())
		{
			Person p=AppContext.getAccountContext().getUser();
			if(taskAllot.getSendSysInfo())//发送系统消息
			{
				
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人即将开始");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人即将结束");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人已超期");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				
				
//				WarnContent wc=new WarnContent();
//				wc.setWarnstyl("任务:"+taskAllot.getTitle());
//				wc.setWarnCont("你对任务:"+taskAllot.getTitle()+"进行了分配");
//			    wc.setReceivID(p.getId()+"");
//				this.getWarncontentService().save(wc);	
			}
			if(taskAllot.getSendMobile())//发送手机短信
			{
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人即将开始");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人即将结束");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人已超期");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				
			}
			if(taskAllot.getSendEmail())//发送email
			{

				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人即将开始");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人即将结束");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的发布人已超期");
					t1.setReId(p.getId()+"");
					t1.setRestyle("发布任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				
			}
//		Person p=AppContext.getAccountContext().getUser();
//		WarnContent wc=new WarnContent();
//		wc.setWarnstyl("任务:"+taskAllot.getTitle());
//		wc.setWarnCont("你对任务:"+taskAllot.getTitle()+"进行了发布");
//	    wc.setReceivID(p.getId()+"");
//		this.getWarncontentService().save(wc);
		}
		/**
		 * 责任人
		 * 当前责任人任务的人
		 */
		if(taskAllot.getRemindAllotPerosn())
		{
			if(taskAllot.getSendSysInfo())//发送系统消息
			{
				
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人即将开始");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人即将结束");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人已超期");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
			}
			if(taskAllot.getSendMobile())//发送手机短信
			{
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人即将开始");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人即将结束");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人已超期");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				
			}
			if(taskAllot.getSendEmail())//发送email
			{

				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人即将开始");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人即将结束");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的责任人已超期");
					t1.setReId(taskAllot.getDutyPerson().getId()+"");
					t1.setRestyle("责任任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				
			}
		}
		/**
		 * 协办人
		 * 当前协办人
		 */
		if(taskAllot.getRemindAllotPerosn())
		{
			if(taskAllot.getSendSysInfo())//发送系统消息
			{
				
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人即将开始");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人即将结束");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人已超期");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				
			
			}
			if(taskAllot.getSendMobile())//发送手机短信
			{
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人即将开始");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人即将结束");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人已超期");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				
			}
			if(taskAllot.getSendEmail())//发送email
			{

				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人即将开始");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人即将结束");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的协办人已超期");
					t1.setReId(taskAllot.getDoPersonId());
					t1.setRestyle("协办任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				
			}
//		Person p=AppContext.getAccountContext().getUser();
//		WarnContent wc=new WarnContent();
//		wc.setWarnstyl("任务:"+taskAllot.getTitle());
//		wc.setWarnCont("你担任了任务:"+taskAllot.getTitle()+"的协办人");
//	    wc.setReceivID(taskAllot.getDoPersonId());
//		this.getWarncontentService().save(wc);
		}
		/**
		 * 参阅人
		 * 当前参阅人
		 */
		if(taskAllot.getRemindAllotPerosn())
		{
			if(taskAllot.getSendSysInfo())//发送系统消息
			{
				
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人即将开始");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人即将结束");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人已超期");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("系统");
					this.getTaskRemindService().save(t1);
				}
				
				
			}
			if(taskAllot.getSendMobile())//发送手机短信
			{
				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人即将开始");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人即将结束");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人已超期");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("短信");
					this.getTaskRemindService().save(t1);
				}
				
			}
			if(taskAllot.getSendEmail())//发送email
			{

				if(taskAllot.getStartRemind())//任务开始前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人即将开始");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("开始之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
					
				}
				if(taskAllot.getStartRemind())//任务结束前提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人即将结束");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("结束之前");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				if(taskAllot.getStartRemind())//任务超期后提醒
				{
					TaskRemind t1=new TaskRemind();
					t1.setReState("1");
					t1.setReContent("你所担任了"+taskAllot.getTitle()+"任务的参阅人已超期");
					t1.setReId(taskAllot.getConsultPersonId());
					t1.setRestyle("参阅任务");
					t1.setRestartTime(dt.getstrTime(startTime));
					t1.setReendTime(dt.getstrTime(endTime));
					t1.setResty("超期之后");
					t1.setSendtype("邮件");
					this.getTaskRemindService().save(t1);
				}
				
			}
//		Person p=AppContext.getAccountContext().getUser();
//		WarnContent wc=new WarnContent();
//		wc.setWarnstyl("任务:"+taskAllot.getTitle());
//		wc.setWarnCont("你担任了任务:"+taskAllot.getTitle()+"的参阅人");
//	    wc.setReceivID(taskAllot.getConsultPersonId());
//		this.getWarncontentService().save(wc);
		}
		
		
		
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		PersonalTaskResult result=this.getPersonalTaskResultService().getPersonalTaskResults(per.getResume().getName());
		DeptTaskResult dtr=this.getDeptTaskResultService().getDeptTaskResult(per.getDept().getName());
//		int d=0;
		if(taskAllot.getId()==null){	
		taskAllot.setAgencyAllotPerson(per.getResume().getName());
		taskAllot.setReleasePerson(per.getResume().getName());
		taskAllot.setState(0);
		taskAllot.setType("未完成");
		taskAllot.setDoState(0);
		taskAllot.setDoType("未完成");
		taskAllot.setShowimg(getAlldays(taskAllot.getStartDate(),taskAllot.getEndDate()));
        this.getTaskAllotService().save(taskAllot);
		//添加个人绩效
		if(result!=null){
			System.out.println(result.getAllTaskNum());
			taskAllot.setPersonalTaskResult(result);
			result.setAllTaskNum(result.getAllTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
		}else{
			result=new PersonalTaskResult();
			taskAllot.setPersonalTaskResult(result);
			result.setType(per.getResume().getName());
			result.setName(per.getResume().getName());
			result.setAllTaskNum(1);
			result.setNormalTaskNum(0);
			result.setAheadTaskNum(0);
			result.setDelayTaskNum(0);
			result.setConductTaskNum(0);
			result.setNoAcceptTaskNUm(0);
			this.getPersonalTaskResultService().save(result);
		}
		//添加单位绩效
		if (dtr!=null) {
			taskAllot.setDeptTaskResult(dtr);
			dtr.setAllTaskNum(dtr.getAllTaskNum()+1);
			this.getDeptTaskResultService().submit(dtr);
		}else{
			dtr =new DeptTaskResult();
			taskAllot.setDeptTaskResult(dtr);
			dtr.setType(taskAllot.getDutyPerson().getResume().getName());
			dtr.setName(taskAllot.getDutyPerson().getDept().getName());
			dtr.setAllTaskNum(1);
			dtr.setNormalTaskNum(0);
			dtr.setAheadTaskNum(0);
			dtr.setDelayTaskNum(0);
			dtr.setConductTaskNum(0);
			dtr.setNoAcceptTaskNUm(0);
			this.getDeptTaskResultService().save(dtr);
		}
//		System.out.println(taskAllot.getDutyPerson().getDept().getName());
//		Integer ss=0 ;
//		Integer deptAll=0;
//		DeptTaskResult dr=new DeptTaskResult();
//		for (DeptTaskResult depts : dtr) {
//			System.out.println(depts.getType());
//			System.out.println(taskAllot.getDutyPerson().getDept().getName());
//			if(depts.getType().equals(taskAllot.getDutyPerson().getDept().getName())){
//				d++;
////				ss=depts.getId();
////				deptAll=depts.getAllTaskNum();
//				dr=depts;
//			}
//		}
//		if(d>0){
//			taskAllot.setDeptTaskResult(deptTaskResult);
//			deptTaskResult.setAllTaskNum(dr.getAllTaskNum()+1);
//			this.getDeptTaskResultService().submit(deptTaskResult);
//		}
//		else{
//			deptTaskResult =new DeptTaskResult();
//			taskAllot.setDeptTaskResult(deptTaskResult);
//			deptTaskResult.setType(taskAllot.getDutyPerson().getDept().getName());
//			deptTaskResult.setName(taskAllot.getDutyPerson().getDept().getName());
//			deptTaskResult.setAllTaskNum(1);
//			deptTaskResult.setNormalTaskNum(0);
//			deptTaskResult.setAheadTaskNum(0);
//			deptTaskResult.setDelayTaskNum(0);
//			deptTaskResult.setConductTaskNum(0);
//			deptTaskResult.setNoAcceptTaskNUm(0);
//			this.getDeptTaskResultService().save(deptTaskResult);
//		}
		this.getTaskAllotService().submit(taskAllot);
	}
		Date date=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyyMMdd");
		String dtt=sf.format(date);
		Date dat=taskAllot.getEndDate();
		String da=sf.format(dat);
		System.out.println(da);
		long num=sf.parse(dtt).getTime();
		long num1=sf.parse(da).getTime();
//		//结束时间
//		int num=(int)(date1);
//		//当前系统时间
//		int num1=(int)(date2);
//		
//		System.out.println(num);
//		System.out.println(num1);
		int day=0;
		
		if(num<num1 && "未完成".equals(taskAllot.getType())){
			day=(int)((num1-num)/(1000*60*60*24));
			taskAllot.setStateName("还有"+String.valueOf(day)+"天");
			result.setConductTaskNum(result.getConductTaskNum()+1);
			dtr.setConductTaskNum(dtr.getConductTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
			this.getDeptTaskResultService().submit(dtr);
		}else if(num<num1 && "完成".equals(taskAllot.getType())){
			day=(int)((num1-num)/(1000*60*60*24));
			taskAllot.setStateName("提前"+String.valueOf(day)+"天");
			result.setAheadTaskNum(result.getAheadTaskNum()+1);
			dtr.setAheadTaskNum(dtr.getAheadTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
			this.getDeptTaskResultService().submit(dtr);
		}else if(num1==num && "未完成".equals(taskAllot.getType())){
			taskAllot.setStateName("今日到期");
			result.setConductTaskNum(result.getConductTaskNum()+1);
			dtr.setConductTaskNum(dtr.getConductTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
			this.getDeptTaskResultService().submit(dtr);
		}else if(num1==num && "完成".equals(taskAllot.getType())){
			taskAllot.setStateName("正常结束");
			result.setNormalTaskNum(result.getNormalTaskNum()+1);
			dtr.setNormalTaskNum(dtr.getNormalTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
			this.getDeptTaskResultService().submit(dtr);
		}else if(num>num1 &&"未完成".equals(taskAllot.getType())){
			day=(int)((num-num1)/(1000*60*60*24));
			taskAllot.setStateName("滞后"+String.valueOf(day)+"天");
			result.setConductTaskNum(result.getConductTaskNum()+1);
			dtr.setConductTaskNum(dtr.getConductTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
			this.getDeptTaskResultService().submit(dtr);
		}else if(num>num1 && "完成".equals(taskAllot.getType())){
			day=(int)((num-num1)/(1000*60*60*24));
			taskAllot.setStateName("逾期"+String.valueOf(day)+"天");
			result.setDelayTaskNum(result.getDelayTaskNum()+1);
			dtr.setDelayTaskNum(dtr.getDelayTaskNum()+1);
			this.getPersonalTaskResultService().submit(result);
			this.getDeptTaskResultService().submit(dtr);
		}
		this.getTaskAllotService().submit(taskAllot);
		return SUCCESS;
	}
	
	
	
	/**
	 * 时间间隔判断
	 * @return
	 */
	
	public String getAlldays(Date startDate,Date endData )
	{
		SimpleDateFormat   sf   =   new   SimpleDateFormat("yyyy-MM-dd");  
		String da=sf.format(startDate);
		String da1=sf.format(endData);
		SimpleDateFormat   df   =   new   SimpleDateFormat("yyyy-MM-dd");  
        Date   firstDate=null;  
        Date   secondDate=null;  
        try   {  
            firstDate   =   df.parse(da);  
            secondDate=df.parse(da1);  
        }  
        catch(Exception   e)   {  
            //   日期型字符串格式错误  
        }  
        int   nDay=(int)((secondDate.getTime()-firstDate.getTime())/(24*60*60*1000));  
        
        if(nDay<=0)
        {
        	return "1";
        }
        else if(nDay==1)
        {
        	return "1";
        }
        else if(nDay==2)
        {
        	return "2";
        }
        else if(nDay==3)
        {
        	return "3";
        }
        else if(nDay==4)
        {
        	return "4";
        }
        else if(nDay==5)
        {
        	return "5";
        }
        else if(nDay==6)
        {
        	return "6";
        }
        else if(nDay>=7)
        {
        	return "7";
        }
       return "1";
  

	}
	@Action("editChecking")
	public String editChecking(){
		return SUCCESS;
	}
	@Action(value = "saveChecking", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
			@Result(name = "error", type = "chain", location = "editChecking?taskAllot=${taskAllot.getId()}") })
	public String saveChecking(){
		Date date=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		taskAllot.setFinishTime(sf.format(date));
		taskAllot.setCheckDate(sf.format(date));
		taskAllot.setState(100);
		taskAllot.setType("完成");
		this.getTaskAllotService().submit(taskAllot);
		
		stateDispose=new StateDispose();
		stateDispose.setTaskAllot(taskAllot);
		this.stateDispose.setFeedbackPerson(per.getResume().getName());
		if(taskAllot.getFinishCheck()==null || "".equals(taskAllot.getFinishCheck().trim())){
			this.stateDispose.setContent(per.getResume().getName()+"对"+taskAllot.getDutyPerson().getResume().getName()+"的任务完成情况进行了审核评分。审核评语：无审核评分："+taskAllot.getPoint());	
		}else{
			this.stateDispose.setContent(per.getResume().getName()+"对"+taskAllot.getDutyPerson().getResume().getName()+"的任务完成情况进行了审核评分。审核评语："+taskAllot.getFinishCheck()+"审核评分："+taskAllot.getPoint());
		}
		
		this.stateDispose.setTime(sf.format(date));
		this.getStateDisposeService().save(stateDispose);
		return SUCCESS;
	}
	

	
	@Action("editFeedback")
	public String editFeedback(){
		return SUCCESS;
	}
//	@Action(value = "saveFeedback", results = {
//			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${taskAllot.getId()}"),
//			@Result(name = "error", type = "chain", location ="editFeedback?taskAllot=${taskAllot.getId()}") })
//	public String saveFeedback(){
//		if(taskAllot.getFeedbackContent()==null || "".equals(taskAllot.getFeedbackContent().trim())){
//			addActionError("请输入反馈内容！");
//			return ERROR;
//		}
//		if(upload!=null){
//			this.taskAllot.setAttach1(FileUtil.getInstance().createAttach(upload, fileName));
//		}
//		taskAllot.setFeedbackContent("[留言]"+taskAllot.getFeedbackContent());
//		this.getTaskAllotService().submit(taskAllot);
//		Date date=new Date();
//		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
//		Person per=new Person();
//		per=AppContext.getAccountContext().currentUser();
//		stateDispose=new StateDispose();
//		stateDispose.setTaskAllot(taskAllot);
//		stateDispose.setFeedbackPerson(per.getResume().getName());
//		stateDispose.setContent(taskAllot.getFeedbackContent());
//
//		stateDispose.setTime(sf.format(date));
//		this.getStateDisposeService().save(stateDispose);
//		return SUCCESS;
//	}
	
	@Action(value = "saveFeedbacks", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskAllot?taskAllot=${stateDispose.getTaskAllot().getId()}"),
			@Result(name = "error", type = "chain", location = "viewTaskAllot?taskAllot=${stateDispose.getTaskAllot().getId()}") })
	public String saveFeedbacks(){
		if(stateDispose.getContent()==null || "".equals(stateDispose.getContent().trim())){
			addActionError("请输入反馈内容！");
			return ERROR;
		}
		if(uploads!=null){
			this.stateDispose.setAttach1(FileUtil.getInstance().createAttach(uploads, uploadsFileName));
		}
		Date date=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		stateDispose.getTaskAllot().setId(stateDispose.getTaskAllot().getId());
		stateDispose.setTaskAllot(stateDispose.getTaskAllot());
		stateDispose.setContent("[留言]"+stateDispose.getContent());
		stateDispose.setFeedbackPerson(per.getResume().getName());
		stateDispose.setTime(sf.format(date));
		this.getStateDisposeService().save(stateDispose);
		this.getTaskAllotService().submit(stateDispose.getTaskAllot());
		return SUCCESS;
	}
	/***任务催办*/
	@Action("editTaskUrge")
	public String editTaskUrge(){
		return SUCCESS;
	}
	@Action(value = "saveTaskUrge", results = {
			@Result(name = "success", type = "redirect", location = "viewTaskInfo?taskAllot=${stateDispose.getTaskAllot().getId()}"),
			@Result(name = "error", type = "chain", location = "viewTaskInfo?taskAllot=${stateDispose.getTaskAllot().getId()}") })
	public String saveTaskUrge(){
		if(stateDispose.getContent()==null || "".equals(stateDispose.getContent().trim())){
			addActionError("请输入反馈信息！");
			return ERROR;
		}
		Date date=new Date();
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		stateDispose.getTaskAllot().setId(stateDispose.getTaskAllot().getId());
		stateDispose.setTaskAllot(stateDispose.getTaskAllot());
		stateDispose.setContent("[督办]"+stateDispose.getContent());
		stateDispose.setFeedbackPerson(per.getResume().getName());
		stateDispose.setTime(sf.format(date));
		this.getStateDisposeService().save(stateDispose);
		this.getTaskAllotService().submit(stateDispose.getTaskAllot());
		return SUCCESS;
	}
	/**我参阅的任务
	 * @throws ParseException */
	@Action("listMyTaskConsult")
	public String listMyTaskConsult() throws ParseException{
		allots=this.getTaskAllotService().getAllTaskAllot();
		for (int i = 0; i <allots.size(); i++) {
			if(allots.size()>0){
				String[] ids=allots.get(i).getConsultPersonId().split(",");			
				for (String pId : ids) {
					if ((AppContext.getAccountContext().currentUser().getId()+"").equals(pId)) {
						allots.get(i).setShowState(AppContext.getAccountContext().currentUser().getId()+":1");
						this.getTaskAllotService().submit(allots.get(i));
					}else{
						
					}
				}	
				Date date=new Date();
				SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
				String dt=sf.format(date);
				Date dat=allots.get(i).getEndDate();
				String da=sf.format(dat);
				long num=sf.parse(dt).getTime();
				long num1=sf.parse(da).getTime();

				int day=0;
				if(num<num1 && "未完成".equals(allots.get(i).getType())){
					day=(int)((num1-num)/(1000*60*60*24));
					allots.get(i).setStateName("还有"+String.valueOf(day)+"天");
				}else if(num<num1 && "完成".equals(allots.get(i).getType())){
					day=(int)((num1-num)/(1000*60*60*24));
					allots.get(i).setStateName("提前"+String.valueOf(day)+"天");
				}else if(num1==num && "未完成".equals(allots.get(i).getType())){
					allots.get(i).setStateName("今日到期");
				}else if(num1==num && "完成".equals(allots.get(i).getType())){
					allots.get(i).setStateName("正常结束");
				}else if(num>num1 && "未完成".equals(allots.get(i).getType())){
					day=(int)((num-num1)/(1000*60*60*24));
					allots.get(i).setStateName("滞后"+String.valueOf(day)+"天");
				}else if(num>num1 && "完成".equals(allots.get(i).getType())){
					day=(int)((num-num1)/(1000*60*60*24));
					allots.get(i).setStateName("逾期"+String.valueOf(day)+"天");
				}
				this.getTaskAllotService().submit(allots.get(i));
			}
		}
		/**查询全部的*/
//		List<TaskAllot> allot=this.getTaskAllotService().getAllTaskAllot();
//		for (int a = 0; a < allot.size(); a++) {
//			if (allot.size()>0) {
//				String[] tids=allot.get(a).getConsultPersonId().split(",");
//				System.out.println(tids);
//				Person person=AppContext.getAccountContext().getUser();
//				System.out.println(person.getId().toString());
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(TaskAllot.class);
		criteria.add(Restrictions.eq("showState", AppContext.getAccountContext().currentUser().getId()+":1"));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getTaskAllotService().listByPage(criteria, pagination));
//		}
//	}
		/**查询未完成的*/
		DetachedCriteria criteria1=this.getPaginationHelper().createQuery(TaskAllot.class);
		criteria1.add(Restrictions.eq("type", "未完成"));	
		criteria1.add(Restrictions.eq("showState", AppContext.getAccountContext().currentUser().getId()+":1"));
		pagination1=this.getPaginationHelper().prepare(pagination1);
		this.setPagination1(this.getTaskAllotService().listByPage(criteria1, pagination1));
		
		/**查询完成的*/
		DetachedCriteria criteria2=this.getPaginationHelper().createQuery(TaskAllot.class);	
//		criteria2.add(Restrictions.eq("agencyAllotPerson", AppContext.getAccountContext().getUser().getResume().getName()))
		criteria2.add(Restrictions.eq("type", "完成"));
		criteria2.add(Restrictions.eq("showState", AppContext.getAccountContext().currentUser().getId()+":1"));
		pagination2=this.getPaginationHelper().prepare(pagination2);
		this.setPagination2(this.getTaskAllotService().listByPage(criteria2, pagination2));
		return SUCCESS;
	}
	
	@Action("viewTaskInfo")
	public String viewTaskInfo(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(StateDispose.class);
		criteria.add(Restrictions.eq("taskAllot.id", taskAllot.getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getStateDisposeService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("viewTaskInfos")
	public String viewTaskInfos(){
		if(taskAllot!=null){
			DetachedCriteria criteria=this.getPaginationHelper().createQuery(StateDispose.class);	
			criteria.add(Restrictions.eq("taskAllot.id", taskAllot.getId()));
			pagination=this.getPaginationHelper().prepare(pagination);
			this.setPagination(this.getStateDisposeService().listByPage(criteria, pagination));
		}
		return SUCCESS;
	}
	@Action(value = "removeTask", results = {
			@Result(name = "success", type = "redirect", location = "listMyTaskAllot"),
			@Result(name = "error", type = "chain", location = "viewTaskAllot") })
	public String removeTask(){
		this.getTaskAllotService().remove(taskAllot);
		return SUCCESS;
	}
	
	@Action("selectAllTaskAllot")
	public String selectAllTaskAllot(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(TaskAllot.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getStateDisposeService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	/***树形列表查看*/
	@Action(value = "loadTaskAllotTree", results = { @Result(name = "success", type = "json",
			params = {"root", "nodes" }) })
	public String loadTaskAllotTree(){
		nodes=new ArrayList<TreeNode>();
		Collection<TaskAllot> task=this.getTaskAllotService().getRootTaskAllot();
		for (TaskAllot taskAllot : task) {
			TreeNode node=new TreeNode();
			node.setId(String.valueOf(taskAllot.getId()));
			node.setText(taskAllot.getTitle());
			addChildNode(taskAllot, node);
			nodes.add(node);
		}
		return SUCCESS;
	}
//	private void addChildNode(TaskAllot taskAllot,TreeNode parentnode){
//		if(taskAllot.getChilds()!=null){
//			for (TaskAllot Allot : taskAllot.getChilds()) {
//				TreeNode node=new TreeNode();
//				node.setId(String.valueOf(taskAllot.getId()));
//				node.setText(taskAllot.getTitle());
//				parentnode.addChildNode(node);
//				addChildNode(Allot, node);
//			}
//		}
//	}
	private void addChildNode(TaskAllot taskAllot,TreeNode parentnode){
		if(taskAllot.getChilds() != null){
			for(TaskAllot task:taskAllot.getChilds()){
				TreeNode node = new TreeNode();
				node.setId(String.valueOf(task.getId()));
				node.setText(task.getTitle());
				parentnode.addChildNode(node);
				addChildNode(task, node);
			}
		}
	}
	
	@Action("listPersonalTaskResult")
	public String listPersonalTaskResult(){
		Person per=new Person();
		per=AppContext.getAccountContext().currentUser();
		PersonalTaskResult taskResult=this.getPersonalTaskResultService().getPersonalTaskResults(per.getResume().getName());
		if(taskResult==null){
			taskResult=new PersonalTaskResult();
			taskResult.setType(per.getResume().getName());
			taskResult.setName(per.getResume().getName());
			taskResult.setAllTaskNum(0);
			taskResult.setNormalTaskNum(0);
			taskResult.setAheadTaskNum(0);
			taskResult.setDelayTaskNum(0);
			taskResult.setConductTaskNum(0);
			taskResult.setNoAcceptTaskNUm(0);
			this.getPersonalTaskResultService().save(taskResult);
		}else{
			System.out.println(taskResult.getId());
			this.getPersonalTaskResultService().submit(taskResult);
		}
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(PersonalTaskResult.class);
		criteria.add(Restrictions.eq("type", per.getResume().getName()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonalTaskResultService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listTaskResultByDept")
	public String listTaskResultByDept(){
//		Person per=new Person();
//		per=AppContext.getAccountContext().currentUser();
//		System.out.println(per.getDept().getName());
//		List<PersonalTaskResult> results=this.getPersonalTaskResultService().getAllPersonalTaskResult();
//		int r=0;
//		for (PersonalTaskResult taskResult : results) {
//			if (taskResult.getName().equals(taskResult.getName())) {
//				r++;
//			}
//		}
//		if(r>0){
//			this.getPersonalTaskResultService().submit(personalTaskResult);
//		}
//		else{
//			personalTaskResult=new PersonalTaskResult();
//			personalTaskResult.setType(per.getDept().getName());
//			personalTaskResult.setName(per.getDept().getName());
//			personalTaskResult.setAllTaskNum(0);
//			personalTaskResult.setNormalTaskNum(0);
//			personalTaskResult.setAheadTaskNum(0);
//			personalTaskResult.setDelayTaskNum(0);
//			personalTaskResult.setConductTaskNum(0);
//			personalTaskResult.setNoAcceptTaskNUm(0);
//			this.getPersonalTaskResultService().save(personalTaskResult);
//		}
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(DeptTaskResult.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonalTaskResultService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("listTaskResultByDepts")
	public String listTaskResultByDepts(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(DeptTaskResult.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonalTaskResultService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	public WarnContent getWarncontent() {
		return warncontent;
	}
	public void setWarncontent(WarnContent warncontent) {
		this.warncontent = warncontent;
	}
	public WarnContentService getWarncontentService() {
		return warncontentService;
	}
	public void setWarncontentService(WarnContentService warncontentService) {
		this.warncontentService = warncontentService;
	}
	public String getStartA() {
		return startA;
	}
	public void setStartA(String startA) {
		this.startA = startA;
	}
	public String getStartAA() {
		return startAA;
	}
	public void setStartAA(String startAA) {
		this.startAA = startAA;
	}
	public String getStartB() {
		return startB;
	}
	public void setStartB(String startB) {
		this.startB = startB;
	}
	public String getStartBB() {
		return startBB;
	}
	public void setStartBB(String startBB) {
		this.startBB = startBB;
	}
	public String getStartC() {
		return startC;
	}
	public void setStartC(String startC) {
		this.startC = startC;
	}
	public String getStartCC() {
		return startCC;
	}
	public void setStartCC(String startCC) {
		this.startCC = startCC;
	}
	public TaskRemindService getTaskRemindService() {
		return taskRemindService;
	}
	public void setTaskRemindService(TaskRemindService taskRemindService) {
		this.taskRemindService = taskRemindService;
	}
	
}
